package com.team.employment.web.app.controller.communal;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.team.employment.common.result.Result;
import com.team.employment.model.entity.CompanyInfo;
import com.team.employment.model.entity.RecruitmentInfo;
import com.team.employment.model.entity.UserFavorite;
import com.team.employment.web.admin.custom.check.IdIsEmptyCheck;
import com.team.employment.web.admin.service.CompanyInfoService;
import com.team.employment.web.admin.service.RecruitmentInfoService;
import com.team.employment.web.app.service.JobApplicationService;
import com.team.employment.web.app.service.UserFavoriteService;
import com.team.employment.web.app.vo.ApplicationResultVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "其它信息管理")
@RestController
@RequestMapping("/app/mixture")
public class MixtureController {

    @Autowired
    private CompanyInfoService companyInfoService;

    @Autowired
    private RecruitmentInfoService recruitmentInfoService;

    @Autowired
    private UserFavoriteService userFavoriteService;

    @Autowired
    private JobApplicationService jobApplicationService;

    @Autowired
    private IdIsEmptyCheck idIsEmptyCheck;

    @Operation(summary = "根据招聘信息id获取公司信息")
    @GetMapping("getCompanyInfoByRecruitmentId/{id}")
    public Result<CompanyInfo> getCompanyInfoByRecruitmentId(@PathVariable Long id){
        CompanyInfo companyInfo = companyInfoService.getCompanyInfoByRecruitmentId(id);
        return Result.ok(companyInfo);
    }


    @Operation(summary = "根据用户id分页查询所有已收藏的招聘信息")
    @GetMapping("pageUserFavorite")
    public Result<IPage<RecruitmentInfo>> pageUserFavorite(@RequestParam Long id ,@RequestParam long current, @RequestParam long size){
        LambdaQueryWrapper<UserFavorite> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(UserFavorite::getUserId,id);
        List<UserFavorite> list = userFavoriteService.list(lambdaQueryWrapper);
        IPage<RecruitmentInfo> page = new Page<>(current, size);
        IPage<RecruitmentInfo> recruitmentInfoIPage = recruitmentInfoService.pageUserFavorite(page,list);
        return Result.ok(recruitmentInfoIPage);
    }

    @Operation(summary = "根据userFavorite_id删除收藏信息")
    @DeleteMapping("removeUserFavoriteById/{id}")
    public Result removeUserFavoriteById(@PathVariable Long id){
        idIsEmptyCheck.idIsEmpty(userFavoriteService,id);
        userFavoriteService.removeById(id);
        return Result.ok();
    }

    @Operation(summary = "根据用户id查看用户的求职结果")
    @GetMapping("getUserJobApplication/{id}")
    public Result<IPage<ApplicationResultVo>> getUserJobApplication(@PathVariable Long id,@RequestParam long current, @RequestParam long size){
        IPage<ApplicationResultVo> vo = jobApplicationService.getUserJobApplication(id,current,size);
        return Result.ok(vo);
    }
}
